#include <cstdio>
#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#include <cstring>

using namespace std;

#define NN 64

class Link
{
public:
    Link()
    :client_socket(-1)
    {
        client_socket = socket(AF_INET,SOCK_STREAM,0);
        if (client_socket==-1)
        {
            perror("socket err\n");
            return;
        }

        struct sockaddr_in server_addr;
        server_addr.sin_family=AF_INET;
        server_addr.sin_port=htons(8888);
        server_addr.sin_addr.s_addr=inet_addr("127.0.0.1");
        if(connect(client_socket,(struct sockaddr*)&server_addr,sizeof(server_addr))==-1)
        {
            perror("connect err\n");
            return;
        }

        char buf[NN]={'\0'};
        while (1)
        {
            printf("请输入要输入的数据:\n");
            cin>>buf;
            send(client_socket,buf,NN,0);
            if (strcmp("quit",buf)==0)
            {
                break;
            }
            recv(client_socket,buf,NN,0);
            cout<<"recv data:"<<buf<<endl;
        }
    }

    ~Link()
    {
        close(client_socket);
    }
private:
    int client_socket;
};

// 用法：./client
int main(int argc, char const* argv[])
{
    Link client;

    return 0;
}